package apof.services
{
	import apof.dao.Dao;
	import apof.model.BudgetStc;
	
	public class BService
	{
		public static function getBudgetName(year:int, month:int):String{
			return ""+year+"年"+(month+1)+"月";
		}
		
		public function getBudget(name:String):BudgetStc {
			var arr:Array=Dao.dp.retriveAll(BudgetStc,null,null,function(b:BudgetStc,...rest) :Boolean {
				return b.name==name;
			});
			var b:BudgetStc=arr[0];
			return b;
		}
		
		public function getAllBudget():Array{
			return Dao.dp.retriveAll(BudgetStc);			
		}
		public function getBudgetList():Array{
			var arr:Array=Dao.dp.retriveAll(BudgetStc);
			var list:Array=[];
			for each(var b:BudgetStc in arr) {
				list.push(b.name);
			}
			return list;
		}
		
		public function getSuggestion():BudgetStc {
			return getBudget("2007年8月");
		}
		
		public function createBudget(year:int,month:int):void {
			var b:BudgetStc=new BudgetStc();
			b.year=year;
			b.month=month;
			Dao.dp.create(b);
		}
	}
}